package iostream;

import java.io.*;

public class IODemo02 {
    public static void main(String[] args) {
        int b = 0; //使用变量b来装调用read()方法时返回的整数
        FileInputStream in = null;
        FileOutputStream out = null;
        try{
            in = new FileInputStream("E:\\new PC\\study\\java学习\\code\\JavaSE\\基础语法\\src\\iostream\\FileInputStreamDemo.java");
            out = new FileOutputStream("E:\\new PC\\study\\java学习\\code\\JavaSE\\基础语法\\src\\iostream\\FileOutputStreamDemo.java");
        }catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        long num = 0; //记录读取的字符数
        try{
            while ((b = in.read()) != -1){
//                System.out.print(b);
                out.write(b);
                System.out.print((char)b);

                num++;
            }
            in.close();
            out.close();
            System.out.println();
            System.out.println("总共读取了" + num + "个字节的文件");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
